<?php
/*******************************************************************************
 * $Date:: Jan 9, 2011 12:20:03 AM                                              $
 * $Revision:                                                                  $
 * $Author:: Tuan Duong                                                        $
 * $Comment::                                                                  $
 ******************************************************************************/ 
/**
 * Description here...
 * 
 * @package Lua
 * @subpackage ##Subpackage##
 * @author Tuan Duong <bacduong[at]gmail[dot]com>
 * @version 
 */

class Lua_Util_Common
{
	/**
	 * Convert from under_score to camelCase
	 * @param string $str
	 * @param bool $capitalise_first_char
	 * @return string
	 */
    public static function toCamelCase($str, $capitalise_first_char = true, $allowHyphen = false) {
        if ($capitalise_first_char) {
            $str[0] = strtoupper($str[0]);
        }
        $func = create_function('$c', 'return strtoupper($c[1]);');
        if ($allowHyphen) {
            return preg_replace_callback('/[_-]([a-z])/', $func, $str);
        } else {
            return preg_replace_callback('/[_]([a-z])/', $func, $str); 
        }
    }
	
    /**
     * Convert from camelCase to under_score
     * @param string $str
     * @param string $delimiter
     * @return string
     */
    public static function fromCamelCase($str, $delimiter = "_") {
        $str[0] = strtolower($str[0]);
        $func = create_function('$c', 'return "' . $delimiter .'" . strtolower($c[1]);');
        return preg_replace_callback('/([A-Z])/', $func, $str);
    }
}